import java.util.*;

public class PrimeNumbers {
    public static void main(String args[]) {
        List<Integer> foundPrimes = new LinkedList<Integer>();
        Scanner in = new Scanner(System.in);
        int upperPrimesLimit = 0;

        System.out.println("Input upper limit for prime numbers list:");
        try {
            upperPrimesLimit = in.nextInt();
        } catch (InputMismatchException e) {
            System.err.println("Your number must be a positive integer value");
        }
        finally{
            in.close();
        }
        if (upperPrimesLimit < 2) {
            System.err.println("Your number must be a positive integer value greater than 1");
            return;
        }

        foundPrimes.add(2);
        for (int numberToCheck = 3; numberToCheck <= upperPrimesLimit; numberToCheck += 2) {
            boolean isPrime = true;

            for (int primeDivider : foundPrimes) {
                if (numberToCheck % primeDivider == 0) {
                    isPrime = false;
                    break;
                }
            }
            if (isPrime) {
                foundPrimes.add(numberToCheck);
            }
        }
        for (int primeNumber : foundPrimes) {
            System.out.print(primeNumber + " ");
        }
        System.out.println("");
    }
}
